package com.snapan.controller;

import com.snapan.common.Result;
import com.snapan.entity.FileHistory;
import com.snapan.service.FileHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/api/history")
@RestController
public class FileHistoryController {

    @Autowired
    private FileHistoryService fileHistoryService;

    @RequestMapping("/clear")
    public Result clearUserHistory(@RequestBody FileHistory fileHistory) {
        if(fileHistoryService.clearUserHistory(fileHistory.getUserId(),fileHistory.getId())>0){
            return Result.success("历史记录删除成功");
        }
        return Result.error("历史记录删除失败，请重试");
    }

    @RequestMapping("/get")
    public List<FileHistory> getUserHistory(@RequestBody FileHistory fileHistory){
        return fileHistoryService.getUserHistory(fileHistory.getUserId(),fileHistory.getCurrentPage());
    }

    @RequestMapping("/record")
    public Result recordHistory(@RequestBody FileHistory fileHistory){
        if(fileHistoryService.recordHistory(fileHistory)>0){
            return Result.success("历史记录添加成功");
        }
        return Result.error("历史记录添加失败");
    }



}
